home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3x / dslib.z / dslib
Encoding:
Text File  |  2002-10-03  |  20.4 KB  |  331 lines

  1.  
  2.  
  3.  
  4. ddddsssslllliiiibbbb((((3333XXXX))))                                                            ddddsssslllliiiibbbb((((3333XXXX))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      dslib: dsopen, dsclose - communicate with generic SCSI devices
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ####iiiinnnncccclllluuuuddddeeee <<<<ddddsssslllliiiibbbb....hhhh>>>>
  13.  
  14.      ssssttttrrrruuuucccctttt ddddssssrrrreeeeqqqq ****ddddssssooooppppeeeennnn((((ooooppppaaaatttthhhh,,,, ooooffffllllaaaaggggssss))))
  15.  
  16.      ddddsssscccclllloooosssseeee((((ddddsssspppp))))
  17.  
  18.      ddddssss____sssshhhhoooowwwwccccmmmmdddd((((ddddsssspppp))))
  19.  
  20.      tttteeeessssttttuuuunnnniiiittttrrrreeeeaaaaddddyyyy00000000((((ddddsssspppp))))
  21.      rrrreeeeqqqquuuueeeessssttttsssseeeennnnsssseeee00003333((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, vvvvuuuu))))
  22.      rrrreeeeaaaadddd00008888((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, llllbbbbaaaa,,,, vvvvuuuu))))
  23.      wwwwrrrriiiitttteeee0000aaaa((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, llllbbbbaaaa,,,, vvvvuuuu))))
  24.      iiiinnnnqqqquuuuiiiirrrryyyy11112222((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, vvvvuuuu))))
  25.      mmmmooooddddeeeesssseeeelllleeeecccctttt11115555((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, ssssaaaavvvveeee,,,, vvvvuuuu))))
  26.      mmmmooooddddeeeesssseeeelllleeeecccctttt55555555((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, ssssaaaavvvveeee,,,, vvvvuuuu))))
  27.      rrrreeeesssseeeerrrrvvvveeeeuuuunnnniiiitttt11116666((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, ttttpppprrrr,,,, ttttppppddddiiiidddd,,,, eeeexxxxtttteeeennnntttt,,,, rrrreeeessssiiiidddd,,,, vvvvuuuu))))
  28.      rrrreeeelllleeeeaaaasssseeeeuuuunnnniiiitttt11117777((((ddddsssspppp,,,, ttttpppprrrr,,,, ttttppppddddiiiidddd,,,, eeeexxxxtttteeeennnntttt,,,, rrrreeeessssiiiidddd,,,, vvvvuuuu))))
  29.      mmmmooooddddeeeesssseeeennnnsssseeee1111aaaa((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, ppppaaaaggggeeeeccccttttrrrrllll,,,, ppppaaaaggggeeeeccccooooddddeeee,,,, vvvvuuuu))))
  30.      mmmmooooddddeeeesssseeeennnnsssseeee5555aaaa((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, ppppaaaaggggeeeeccccttttrrrrllll,,,, ppppaaaaggggeeeeccccooooddddeeee,,,, vvvvuuuu))))
  31.      mmmmooooddddeeeesssseeeennnnsssseeeeNNNNBBBB____5555aaaa((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, ppppaaaaggggeeeeccccttttrrrrllll,,,, ppppaaaaggggeeeeccccooooddddeeee,,,, vvvvuuuu))))
  32.      sssseeeennnnddddddddiiiiaaaaggggnnnnoooossssttttiiiicccc1111dddd((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, sssseeeellllffff,,,, ddddooooffffllll,,,, uuuuooooffffllll,,,, vvvvuuuu))))
  33.  
  34.      rrrreeeeaaaaddddccccaaaappppaaaacccciiiittttyyyy22225555((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, llllbbbbaaaa,,,, ppppmmmmiiii,,,, vvvvuuuu))))
  35.      rrrreeeeaaaaddddeeeexxxxtttteeeennnnddddeeeedddd22228888((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, llllbbbbaaaa,,,, vvvvuuuu))))
  36.      wwwwrrrriiiitttteeeeeeeexxxxtttteeeennnnddddeeeedddd2222aaaa((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, llllbbbbaaaa,,,, vvvvuuuu))))
  37.  
  38.      ggggeeeettttffffdddd((((ddddsssspppp))))
  39.      ddddoooossssccccssssiiiirrrreeeeqqqq((((ffffdddd,,,, ddddsssspppp))))
  40.      vvvvooooiiiidddd ffffiiiillllllllgggg0000ccccmmmmdddd((((ddddsssspppp,,,, ccccmmmmddddbbbbuuuuffff,,,, bbbb0000,,,, ............,,,, bbbb5555))))
  41.      vvvvooooiiiidddd ffffiiiillllllllgggg1111ccccmmmmdddd((((ddddsssspppp,,,, ccccmmmmddddbbbbuuuuffff,,,, bbbb0000,,,, ............,,,, bbbb9999))))
  42.      vvvvooooiiiidddd ffffiiiillllllllgggg2222ccccmmmmdddd((((ddddsssspppp,,,, ccccmmmmddddbbbbuuuuffff,,,, bbbb0000,,,, ............,,,, bbbb9999))))
  43.      vvvvooooiiiidddd ffffiiiillllllllgggg5555ccccmmmmdddd((((ddddsssspppp,,,, ccccmmmmddddbbbbuuuuffff,,,, bbbb0000,,,, ............,,,, bbbb11111111))))
  44.      vvvvooooiiiidddd ffffiiiillllllllddddssssrrrreeeeqqqq((((ddddsssspppp,,,, ddddaaaattttaaaa,,,, ddddaaaattttaaaalllleeeennnn,,,, ffffllllaaaaggggssss))))
  45.      vvvvooooiiiidddd vvvvttttoooossssttttrrrr((((vvvvaaaalllluuuueeee,,,, ttttaaaabbbblllleeee))))
  46.  
  47.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt ddddssssddddeeeebbbbuuuugggg;;;;
  48.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt ddddssss____ddddeeeeffffaaaauuuulllltttt____ttttiiiimmmmeeeeoooouuuutttt;;;;
  49.      eeeexxxxtttteeeerrrrnnnn lllloooonnnngggg ddddssssrrrreeeeqqqqffffllllaaaaggggssss;;;;
  50.      DDDDSSSSDDDDBBBBGGGG((((ssssttttaaaatttteeeemmmmeeeennnntttt;;;; ............))))
  51.  
  52.      ssssttttrrrruuuucccctttt ddddssssrrrreeeeqqqq ****ddddsssspppp;;;;
  53.      ssssttttrrrruuuucccctttt vvvvttttaaaabbbb ****ttttaaaabbbblllleeee;;;;
  54.      cccchhhhaaaarrrr ****ooooppppaaaatttthhhh,,,, ****ccccmmmmddddbbbbuuuuffff,,,, ****ddddaaaattttaaaa;;;;
  55.      cccchhhhaaaarrrr bbbb0000,,,, ............,,,, bbbb9999,,,, ddddooooffffllll,,,, eeeexxxxtttteeeennnntttt,,,, ppppaaaaggggeeeeccccooooddddeeee,,,, ppppaaaaggggeeeeccccttttrrrrllll,,,, ppppmmmmiiii,,,, rrrreeeessssiiiidddd,,,,
  56.           ssssaaaavvvveeee,,,, sssseeeellllffff,,,, ttttppppddddiiiidddd,,,, ttttpppprrrr,,,, uuuuooooffffllll,,,, vvvvuuuu;;;;
  57.      iiiinnnntttt ffffdddd,,,, ooooffffllllaaaaggggssss;;;;
  58.      lllloooonnnngggg ddddaaaattttaaaalllleeeennnn,,,, llllbbbbaaaa,,,, vvvvaaaalllluuuueeee;;;;
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ddddsssslllliiiibbbb((((3333XXXX))))                                                            ddddsssslllliiiibbbb((((3333XXXX))))
  71.  
  72.  
  73.  
  74. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  75.      These routines form the basis for a simplified interface to _d_s(7M)
  76.      devices.  They are included in a program by compiling with the ----llllddddssss
  77.      option.  An application would typically use _d_s_o_p_e_n, _d_s_c_l_o_s_e, and a set of
  78.      command-specific routines such as _t_e_s_t_u_n_i_t_r_e_a_d_y_0_0.  The source to this
  79.      library can be obtained by loading the _i_r_i_x__d_e_v._g_i_f_t_s._s_c_s_i subsystem,
  80.      with the source code for the library in the files _d_s_t_a_b._c and _d_s_l_i_b._c in
  81.      the directory /_u_s_r/_s_h_a_r_e/_s_r_c/_i_r_i_x/_e_x_a_m_p_l_e_s/_s_c_s_i.  There are also several
  82.      sample programs using the dslib library in the same directory.
  83.  
  84.      The number of truly general SCSI commands is quite limited, so provision
  85.      is made for supporting vendor-specific commands.  This is normally done
  86.      by using one of the existing routines as a template, and creating a new
  87.      routine of your own.  This might be useful if support for a SCSI command
  88.      group other than Group 0, 1, 2, or 5 is needed.  It is expected that most
  89.      non-trivial uses of the library will involve creating or modifying
  90.      existing routines.  As of release 4.0 of IRIX, any SCSI command length
  91.      from 1 to 12 bytes is supported by the underlying kernel drivers,
  92.      providing the ds_cmdlen field is set correctly.
  93.  
  94.      A set of helper routines (_f_i_l_l_g_0_c_m_d and so on) are used as the basis for
  95.      creating your own routines.  The utility function _d_s__s_h_o_w_c_m_d(_d_s_p) can be
  96.      used to show information about the most recently executed command, in
  97.      cases where the use of _d_s_d_e_b_u_g is too verbose.  _t_e_s_t_u_n_i_t_r_e_a_d_y_0_0, for
  98.      instance, is implemented as:
  99.  
  100.           testunitready00(dsp)
  101.           struct dsreq *dsp;
  102.           {
  103.             fillg0cmd(dsp, CMDBUF(dsp), G0_TEST, 0, 0, 0, 0, 0);
  104.             filldsreq(dsp, 0, 0, DSRQ_READ|DSRQ_SENSE);
  105.             return(doscsireq(getfd(dsp), dsp));
  106.           }
  107.  
  108.      Note that many of these routines depend upon the exact setup of the _d_s_r_e_q
  109.      structure used by _d_s_o_p_e_n.  It is therefore _n_o_t recommended that users
  110.      attempt to use independently derived _d_s_r_e_q structures with them.
  111.  
  112.      _d_s_o_p_e_n passes _o_p_a_t_h and _o_f_l_a_g_s to the _o_p_e_n system call.  If the _o_p_e_n
  113.      succeeds, _d_s_o_p_e_n allocates and fills a _d_s_r_e_q structure, along with some
  114.      associated context information.  _d_s_c_l_o_s_e deallocates the specified _d_s_r_e_q
  115.      structure, then calls _c_l_o_s_e to close the device.
  116.  
  117.      _f_i_l_l_g_0_c_m_d, _f_i_l_l_g_1_c_m_d, _f_i_l_l_g_2_c_m_d, and _f_i_l_l_g_5_c_m_d are used to fill Group 0,
  118.      1, 2, and 5 command buffers, respectively.  _f_i_l_l_d_s_r_e_q fills a _d_s_r_e_q
  119.      structure with commonly needed data.  The value of dsreqflags is ORed
  120.      into the _d_s__f_l_a_g_s field.  This is useful if you want a flag (such as
  121.      DSRQ_SENSE) set for some or all commands, as it allows you to avoid
  122.      duplicating the library routines when you need a special flag set.  It
  123.      also sets the default timeout (for functions that do not explicitly set a
  124.      timeout).  The timeout is set from the global variable
  125.      _d_s__d_e_f_a_u_l_t__t_i_m_e_o_u_t, and that variable is initialized to 10 seconds.  It
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ddddsssslllliiiibbbb((((3333XXXX))))                                                            ddddsssslllliiiibbbb((((3333XXXX))))
  137.  
  138.  
  139.  
  140.      may be changed for applications that want longer default timeouts.
  141.      Individual functions may still need to set longer (or shorter) timeouts,
  142.      after calling _f_i_l_l_d_s_r_e_q.  _d_o_s_c_s_i_r_e_q issues the SCSI _i_o_c_t_l, performs a
  143.      variety of error-handling functions, and returns the SCSI status byte.
  144.      Also of interest on return is the ds_ret field, which is 0 on successful
  145.      returns, and on failures indicates what type of error occurred (the
  146.      DSRT_* values in <_s_y_s/_d_s_r_e_q._h>.
  147.  
  148.      _d_s__v_t_o_s_t_r Takes a value, and a table to look it up in.  If the value is
  149.      found in the given table, a string describing the value is returned, else
  150.      the empty string.  Five tables are provided:
  151.  
  152.      _d_s_r_q_n_a_m_e_t_a_b    for the DSRQ_* flags
  153.      _d_s_r_t_n_a_m_e_t_a_b    for the DSRT_* flags
  154.      _c_m_d_s_t_a_t_u_s_t_a_b   for the SCSI status byte return in ds_status
  155.      _m_s_g_n_a_m_e_t_a_b     for the SCSI message bytes
  156.      _c_m_d_n_a_m_e_t_a_b     for the SCSI commands, such as Testunitready (value is the
  157.                     command byte; G0_TEST in this case)
  158.  
  159.      The _d_s_d_e_b_u_g variable, and the _D_S_D_B_G() macro can be used to enable debug
  160.      _p_r_i_n_t_fs, and to add your own.  If the _d_s_d_e_b_u_g variable is non-zero,
  161.      debugging information is printed by the library routines.  The _D_S_D_B_G
  162.      macro is used for this purpose.  A more or less arbitrary sequence of
  163.      statements can be used within the parentheses of the _D_S_D_B_G macro, but
  164.      some form of print statement is most frequently used.
  165.  
  166.      Overlay structures define the layouts of the three (Group 0, 1, 6) Common
  167.      Command Set command buffers.  Bytes are named both by position (g0_b0)
  168.      and by typical function in the command buffer (g1_op_code).
  169.  
  170.      Mnemonic names are also defined for all CCS command codes (G0_TEST),
  171.      message bytes (MSG_ABORT), and status bytes (STA_BUSY).  There are also a
  172.      number of macros suitable for accessing _d_s_r_e_q structures, SCSI byte and
  173.      bit fields, etc.
  174.  
  175.      A set of structures contains values, name strings, and descriptions for
  176.      commonly used codes and values.  The structures document DSRQ_* and
  177.      DSRT_* codes, CCS command codes, and CCS status and message bytes.  They
  178.      are principally useful in generating explicit error messages.
  179.  
  180.  
  181.      EXAMPLE PROGRAM
  182.  
  183.      The following code fragment illustrates simple use of the library, and of
  184.      some /_d_e_v/_s_c_s_i support macros.  If you have installed the
  185.      _4_D_g_i_f_t_s._s_r_c._f_u_l_l image, the full source code for this program can be
  186.      found in the file /_u_s_r/_p_e_o_p_l_e/_4_D_g_i_f_t_s/_e_x_a_m_p_l_e_s/_d_e_v_i_c_e_s/_d_e_v_s_c_s_i/_i_n_q_u_i_r_e._c,
  187.  
  188.           while (--argc > 0) {
  189.             fn = *++argv;
  190.             printf("%-17s  ", fn);
  191.             if ((dsp = dsopen(fn, O_RDONLY)) == NULL) {
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ddddsssslllliiiibbbb((((3333XXXX))))                                                            ddddsssslllliiiibbbb((((3333XXXX))))
  203.  
  204.  
  205.  
  206.             fflush(stdout);
  207.               perror("cannot open");
  208.               continue;
  209.             }
  210.  
  211.             if(inquiry12(dsp, inqbuf, sizeof inqbuf, 0) != 0)
  212.               printf("%-10s inquiry failure0, "---");
  213.             else {
  214.               pdt = DATABUF(dsp)[0] & 0x7F;
  215.               if (DATASENT(dsp) >= 1)
  216.                 printf("%-10s", pdt_types[(pdt<NPDT) ? pdt : NPDT-1]);
  217.               if (DATASENT(dsp) >= 16) printf("  %-12.8s", &DATABUF(dsp)[8]);
  218.               if (DATASENT(dsp) >= 32) printf("  %.16s",   &DATABUF(dsp)[16]);
  219.               if (DATASENT(dsp) >= 36) printf("  %.4s",    &DATABUF(dsp)[32]);
  220.               /*  do test unit ready only if inquiry successful, since many
  221.                 devices, such as tapes, return inquiry info, even if
  222.                 not ready (i.e., no tape in a tape drive). */
  223.               if(testunitready00(dsp) != 0) {
  224.                 printf("  %s0,
  225.                   (RET(dsp)==DSRT_NOSEL) ? "cannot select" : "not ready");
  226.               }
  227.               else
  228.                 printf("  ready0);
  229.             }
  230.             dsclose(dsp);
  231.           }
  232.  
  233.      Each device is opened, and the necessary data structures created.  An
  234.      inquiry is done to see if the device exists; if so, it's type is printed.
  235.      A test unit ready is done to see if the device is ready for I/O.
  236.      Finally, the device is closed, releasing the data structures.  The normal
  237.      output is of the form:
  238.  
  239.           /dev/scsi/sc0d2l0   Tape     ARCHIVE       VIPER 150  21247  -605  not ready
  240.  
  241.  
  242. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  243.      _d_s_o_p_e_n returns a NNNNUUUULLLLLLLL pointer on failure.  _d_o_s_c_s_i_r_e_q returns -1 on
  244.      absolute failure, and the status byte otherwise.  A status byte of 0xff
  245.      indicates an invalid status byte because the scsi command didn't
  246.      complete.  The RET(dsp) macro returns a result code, which can be
  247.      consulted for any error or 'unusual' status from the driver; a value of 0
  248.      indicates a normal return.
  249.  
  250. NNNNOOOOTTTTEEEE
  251.      A common failure occurs when the byte count passed to the dslib routines
  252.      doesn't match the byte count implied by the values in the SCSI command
  253.      descriptor (as filled by _f_i_l_l_g_0_c_m_d and so on).  This is particularly
  254.      common with _r_e_a_d_0_8,_w_r_i_t_e_0_a,_r_e_a_d_e_x_t_e_n_d_e_d_2_8, and _w_r_i_t_e_e_x_t_e_n_d_e_d_2_a.  This is
  255.      because these commands occur in a number of device specific forms.  If
  256.      you get console error messages similar to
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. ddddsssslllliiiibbbb((((3333XXXX))))                                                            ddddsssslllliiiibbbb((((3333XXXX))))
  269.  
  270.  
  271.  
  272.           SCSI Bus=# ID=# LUN=#: Too much data (probable SCSI bus cabling problem)
  273.  
  274.      then you are probably seeing this kind of mismatch.  See the comments in
  275.      the _d_s_l_i_b._c source file for more information.
  276.  
  277.      As of IRIX 5.1, this library and the underlying driver are supported on
  278.      all Silicon Graphics SCSI adapters (wd93, wd95, and jag) for all
  279.      controllers that are installed.  Prior to that release, it was supported
  280.      only on the wd93 controller.
  281.  
  282.      As of IRIX 5.1, devices can be open via both the _d_s and other high level
  283.      drivers at the same time (except for _t_p_s_c).  Only one program can have
  284.      any _d_s device open at a time, however.
  285.  
  286. FFFFIIIILLLLEEEESSSS
  287.      /dev/scsi/*
  288.  
  289. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  290.      hinv(1M), ds(7M).
  291.  
  292.      IRIX Device Driver Programmer's Guide
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.